package com.songlanyun.common.enums;


import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import com.songlanyun.common.drive.IntegerEnum;

import java.util.Objects;

/**
 * 账单 相关枚举
 */
public class UserBillConstant {

    /**
     * 账单类型（0，支出（提现），1收入（结算分佣所得））
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum BillType implements IntegerEnum<Integer> {

        EXPENDITURE(0, "支出"),//出账

        INCOME(1, "收入"),//入账
        ;


        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        BillType(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static UserBillConstant.BillType getByCode(int code) {
            for (UserBillConstant.BillType value : UserBillConstant.BillType.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }

    /**
     * 收入模式：0、非收入，1分润所得
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum InnerMode implements IntegerEnum<Integer> {

        SPENDING(0, "非收入"),

        FENRUN_INCOME(1, "分润所得"),

        BUY_INCOME(2, "购物所得"),

        REGISTER(3, "首次注册送贡献值"),

        SHARE_INCOME(4, "分享提成"),

        ADMIN_ADD(5, "平台后台赠送"),

        ;


        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        InnerMode(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static UserBillConstant.InnerMode getByCode(int code) {
            for (UserBillConstant.InnerMode value : UserBillConstant.InnerMode.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }

        public static String getMsgByCode(int code) {
            InnerMode[] innerModes = values();
            for (InnerMode innerMode : innerModes) {
                if (innerMode.getCode().equals(code)) {
                    return innerMode.getMsg();
                }
            }
            return null;
        }
    }

    /**
     * 支出模式：（0，非支出，1提现,2佣金转存余额）
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum OuterMode implements IntegerEnum<Integer> {

        SPENDING(0, "非支出"),

        CONSUMPTION_RELEASES_POINTS(1, "贡献值释放积分"),

        ADMIN_DEV(2, "平台后台扣减"),

        WITHDRAW(3, "兑换"),

        COMMISSION_TO_BALANCE(4, "佣金转存余额"),

        MONTHLY_DIVIDENDS(5, "月度分红"),

        ORDER_DIVIDENDS(6, "会员下单分红"),

        WRITE_OFF(7, "订单核销");


        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        OuterMode(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static UserBillConstant.OuterMode getByCode(int code) {
            for (UserBillConstant.OuterMode value : UserBillConstant.OuterMode.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }

        public static String getMsgByCode(int code) {
            OuterMode[] outerModes = values();
            for (OuterMode outerMode : outerModes) {
                if (outerMode.getCode().equals(code)) {
                    return outerMode.getMsg();
                }
            }
            return null;
        }
    }

}
